package com.ld.security.gateway.controller;


import com.ld.security.gateway.filter.TestGatewayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@RequestMapping("/server")
@RestController
public class ServerController {

    @Autowired
    private LoadBalancerClient loadBalancer;
    @Autowired
    private DiscoveryClient discoveryClient;


    /**
     * 获取所有服务
     */
    @RequestMapping(value = "/page",method = RequestMethod.GET)
    public Object page() {
        List list =  discoveryClient.getServices().stream().map(val -> {
            HashMap map = new HashMap();
            map.put("id",val);
            map.put("label",val);
            return map;
        }).collect(Collectors.toList());
       return  list;
    }




}
